package com.loubii.account.app;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.loubii.account.bean.AccountModel;
import com.loubii.account.bean.UserBean;
import com.loubii.account.db.DaoMaster;
import com.loubii.account.db.DaoSession;
import com.loubii.account.db.database.DBManager;
import com.loubii.account.db.database.DbHelper;

/**
 * @author luo
 * @date 2017/8/23
 */
public class AccountApplication extends Application {

    private static final String DB_NAME = "loubii.db";//数据库名称
    private static AccountApplication mInstance;
    private static DaoSession daoSession;
    public static float screenDensity;

    public static Context getInstance() {
        return mInstance;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        //初始化greendao
        DbHelper.getInstance().init(this);
        initGreenDao(this);

    }

    public static DBManager<AccountModel, Long> getDbManager() {
        return DbHelper.getInstance().author();
    }

    private static void initGreenDao(Context context) {
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, DB_NAME);
        SQLiteDatabase db = helper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoSession() {
        return daoSession;
    }
}
